using System;
using System.Collections.Generic;
using UnityEngine;

public class CollectionThemeSceneHandler : MonoBehaviour, IGameScene, IHandlerBase
{
	public void DoDataExchange()
	{
	}

	public void OnEnterScene(object param)
	{
		this.prevScene = (string)param;
		if (Scene.IsPopupOpen("SettingPopup"))
		{
			Scene.ClosePopup("SettingPopup", null);
		}
		foreach (PictureThemeWidgetHandler pictureThemeWidgetHandler in this.widgets)
		{
			UnityEngine.Object.Destroy(pictureThemeWidgetHandler.gameObject);
		}
		this.widgets.Clear();
		this.top.transform.localPosition = new Vector3(this.top.transform.localPosition.x, BlockBannerAnchor.GetTopPositionY(), this.top.transform.localPosition.z);
		float bannerPositionY = BlockBannerAnchor.GetBannerPositionY();
		this.bottom.transform.localPosition = new Vector3(this.bottom.transform.localPosition.x, bannerPositionY, this.bottom.transform.localPosition.z);
		this.CreatePictureList();
	}

	public void OnLeaveScene()
	{
	}

	private bool CreatePictureList()
	{
		Vector3 zero = Vector3.zero;
		Vector3 vector = Scene.CurrentScene().transform.InverseTransformPoint(this.topDown.transform.position);
		Vector3 vector2 = Scene.CurrentScene().transform.InverseTransformPoint(this.bottomUp.transform.position);
		zero.y = vector.y;
		zero.z = -1f;
		zero.y -= 4f;
		List<PictureThemeWidgetHandler> list = new List<PictureThemeWidgetHandler>();
		for (int i = 0; i < CollectionTheme.names.Length; i++)
		{
			PictureThemeWidgetHandler pictureThemeWidgetHandler = Widget.Create<PictureThemeWidgetHandler>();
			pictureThemeWidgetHandler.transform.parent = this.pageContents.transform;
			zero.x = ((i % 2 != 0) ? 3.1f : -3.1f);
			pictureThemeWidgetHandler.transform.localPosition = zero;
			if (i % 2 != 0)
			{
				zero.y -= this.widgetInterval;
			}
			pictureThemeWidgetHandler.transform.localScale = Vector3.one;
			pictureThemeWidgetHandler.gameObject.name = string.Format("{0:D3}.{1}", i, pictureThemeWidgetHandler.gameObject.name);
			pictureThemeWidgetHandler.SetData(CollectionTheme.names[i]);
			this.widgets.Add(pictureThemeWidgetHandler);
			list.Add(pictureThemeWidgetHandler);
		}
		GameObject gameObject = this.pageContents.gameObject;
		Bounds bounds = new Bounds(gameObject.transform.position, Vector3.zero);
		for (int j = 0; j < list.Count; j++)
		{
			bounds.Encapsulate(list[j].GetComponent<Renderer>().bounds);
		}
		this.pageArea.ContentLength = bounds.size.y + 3f;
		this.pageArea.VisibleAreaLength = Mathf.Abs(vector.y) + Mathf.Abs(vector2.y);
		return true;
	}

	private void OnClick_Form_back()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		Scene.ChangeTo(this.prevScene, null);
	}

	public void OnClickTheme(PictureThemeWidgetHandler theme)
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		DWATTHelper.logEvent("Collection", new object[]
		{
			"ThemeEnter",
			theme.themeName
		});
		BlockPopupTransition.PopupAnimation(delegate
		{
			Scene.QueuePopup("CollectionPopup", theme.themeName, delegate(object close)
			{
				theme.SetData(theme.themeName);
			});
		});
	}

	private void OnEscape()
	{
		Scene.ChangeTo(this.prevScene, null);
	}

	private void ScrollYCallBack()
	{
		if (this.pageArea.Value >= 0.025f)
		{
			if (this.pageArea.Value > 0.975f)
			{
			}
		}
		if (this.pageArea.ContentLength < this.pageArea.VisibleAreaLength)
		{
		}
	}

	[SerializeField]
	private tk2dCamera cam;

	[SerializeField]
	private GameObject curtain;

	public GameObject pageContents;

	public tk2dUIScrollableArea pageArea;

	public GameObject top;

	public GameObject topDown;

	public GameObject bottom;

	public GameObject bottomUp;

	private int currentPage;

	private List<PictureThemeWidgetHandler> widgets = new List<PictureThemeWidgetHandler>();

	private float originalwidgetInterval = 4f;

	private float widgetInterval = 7f;

	private string prevScene = "IntroScene";
}
